home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 6 / 006.d81 / dos #12 < prev    next >
Text File  |  2022-08-26  |  3KB  |  206 lines

  1.        DOS & DON'TS -- Part 12
  2.        -----------------------
  3.  
  4.  
  5.    Last issue we discussed the 1541
  6.  
  7. Disk Drive's 'channels', particularly
  8.  
  9. the Command/Error Channel (CEC), or
  10.  
  11. Channel #15.  This time we will dis-
  12.  
  13. cuss how to actually use the 1541 as
  14.  
  15. more than just a place to store prog-
  16.  
  17. rams, but also as a place to put data
  18.  
  19. to be used by your programs.
  20.  
  21.  
  22.    A 'file' is a collection of data
  23.  
  24. bytes grouped together and given a
  25.  
  26. name, and stored on a mass-storage de-
  27.  
  28. vice such as the 1541.  These bytes
  29.  
  30. may be anything that the computer can
  31.  
  32. use and recognize.  They may be the
  33.  
  34. ASCII characters which make up text,
  35.  
  36. or they may be other kinds of data.
  37.  
  38. BASIC programs almost always use the
  39.  
  40. ASCII means to represent data.
  41.  
  42.  
  43.    A file is called a 'sequential'
  44.  
  45. file if it can only be accessed from
  46.  
  47. beginning to end.  It is called a
  48.  
  49. 'relative' file if it is divided into
  50.  
  51. equally-sized 'records' that can be
  52.  
  53. referenced in any order.  A sequential
  54.  
  55. file might be used to store text, such
  56.  
  57. as a letter or report; or any other
  58.  
  59. information which need not be accessed
  60.  
  61. in a relative fashion, but can be used
  62.  
  63. sequentially.
  64.  
  65.  
  66.    For small amounts of data that must
  67.  
  68. be accessed in a relative fashion such
  69.  
  70. as a personal mailing list, it is pos-
  71.  
  72. sible to use the data in memory in the
  73.  
  74. form of one or more BASIC arrays, and
  75.  
  76. to store the arrays sequentially in a
  77.  
  78. sequential file when the program is
  79.  
  80. done with them, so they can be read in
  81.  
  82. next time.
  83.  
  84.  
  85.    The important things to remember a-
  86.  
  87. bout sequential files are that they
  88.  
  89. must be accessed from beginning to end
  90.  
  91. and that (at least when used from BA-
  92.  
  93. SIC) they hold data in a form which
  94.  
  95. can be used by the BASIC INPUT# state-
  96.  
  97. ment.  That means that each data item,
  98.  
  99. meaning each peace of data that will
  100.  
  101. go to a particular variable, must be
  102.  
  103. separated from adjacent pieces of data
  104.  
  105. in the file by a comma or a carriage
  106.  
  107. return.  For example, if you had a BA-
  108.  
  109. SIC program that asked a question such
  110.  
  111. as:
  112.  
  113.  
  114.    50 INPUT 'WHO ARE YOU AND HOW OLD
  115.     ARE YOU? '; NA$, AGQ
  116.  
  117.  
  118. it would display:
  119.  
  120.  
  121.    WHO ARE YOU AND HOW OLD ARE YOU
  122.    ?
  123.  
  124.  
  125. and you could choose to answer either
  126.  
  127. by separating your name and age with
  128.  
  129. a comma, as in:
  130.  
  131.  
  132.    WHO ARE YOU AND HOW OLD ARE YOU
  133.    ? JOEL REA, 25
  134.  
  135.  
  136. or by pressing RETURN, as in:
  137.  
  138.  
  139.    WHO ARE YOU AND HOW OLD ARE YOU
  140.    ? JOEL REA
  141.    ?? 25
  142.  
  143.  
  144. But if you didn't separate them, or
  145.  
  146. tried to use another character as a
  147.  
  148. separator, this would happen:
  149.  
  150.  
  151.    WHO ARE YOU AND HOW OLD ARE YOU
  152.    ? JOEL REA 25
  153.    ??
  154.  
  155.  
  156. The program would assign 'JOEL REA 25'
  157.  
  158. to NA$, and still need data for AG!
  159.  
  160.  
  161.    As far as a BASIC program is con-
  162.  
  163. cerned, a sequential file is merely
  164.  
  165. stored INPUT.  Thus, when writing to
  166.  
  167. the file, you must write a separator
  168.  
  169. between each piece of data.  This sep-
  170.  
  171. arator can be a comma or a carriage
  172.  
  173. return (CHR$(13)).  I recommend using
  174.  
  175. the return by assigning it to the var-
  176.  
  177. iable R$ near the beginning of your
  178.  
  179. program:
  180.  
  181.  
  182.    10 R$=CHR$(13): REM CARRIAGE RE-
  183.    TURN FOR DATA SEPARATOR IN FILE.
  184.  
  185.  
  186. Then you can use it easily when you
  187.  
  188. need to write data:
  189.  
  190.  
  191.    160 PRINT#8, NA$; R$; AG
  192.  
  193.  
  194. A Return is automatically written af-
  195.  
  196. ter the data in a PRINT# statement if
  197.  
  198. no comma or semicolon appears at the
  199.  
  200. end of the statement (just like PRINT-
  201.  
  202. ing to the screen!).
  203.  
  204.  
  205. ======== continued in Part 13 ========
  206.